﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Reflection;
using System.Diagnostics;
using System.Net;
using WebProxyApplication.Certificate;
using System.Threading;
using System.Configuration;

namespace WebProxyApplication
{
    public class Global : System.Web.HttpApplication
    {

        void Application_Start(object sender, EventArgs e)
        {
            Version version;
            Assembly thisAssembly;

            thisAssembly = Assembly.GetExecutingAssembly();
            version = thisAssembly.GetName().Version;
            ProxyLogger.Log.InfoFormat("Web proxy V{0}.{1}.{2}.{3} started (PID {4}).", version.Major, version.Minor, version.Build, version.Revision, Process.GetCurrentProcess().Id);

            ServicePointManager.ServerCertificateValidationCallback += ProxyCertVerifier.ValidateServerCertficate;
            if (Convert.ToBoolean(ConfigurationManager.AppSettings["LookupPhishIPAddresses"]))
            {
                Utils.LoadPhishIPAddressDictionaryInBackground();
            }
        }

        void Application_End(object sender, EventArgs e)
        {
            ProxyLogger.Log.Info("Web proxy ended");

        }

        void Application_Error(object sender, EventArgs e)
        {
            // Code that runs when an unhandled error occurs

        }

        void Session_Start(object sender, EventArgs e)
        {
            // Code that runs when a new session is started

        }

        void Session_End(object sender, EventArgs e)
        {
            // Code that runs when a session ends. 
            // Note: The Session_End event is raised only when the sessionstate mode
            // is set to InProc in the Web.config file. If session mode is set to StateServer 
            // or SQLServer, the event is not raised.

        }

    }
}
